/**
 *  *2010-7-18 下午11:39:24  add 
 */
package com.base.myproject.client.Excel;

import java.util.ArrayList;

import com.base.myproject.client.ui.BaseGrid;
import com.extjs.gxt.ui.client.data.ModelData;

/**
 * 将grid的显示内容转变为ExcelObject
 * @author Administrator
 *2010-7-18
 * javazgw@gmail.com
 */
public class Grid2ExcelBO {

	static Grid2ExcelBO g2ebo = null;
	private Grid2ExcelBO()
	{
		
	}
	
	public static Grid2ExcelBO getInstance()
	{
		if(g2ebo==null)
			g2ebo = new Grid2ExcelBO();
		return g2ebo;
	}
	
	public ExcelObject getEO(BaseGrid<ModelData> bg)
	{
		ExcelObject eo = new ExcelObject();
		int count = bg.getStore().getCount();
		int headercount =bg.getView().getHeader().getHeads().size();
		for(int i=0;i<headercount;i++)
		{
			//GWT.log("headertext2= "+gridpanel.getBg().getView().getHeader().getHeads().get(i).getHeaderText());
			String header=null;
			if(bg.getView().getHeader().getHeads().get(i)!=null)
			header = bg.getView().getHeader().getHeads().get(i).getHeaderText();
			
			eo.addHeader(header==null?"":header);
		}
		for(int i=0;i<count;i++)
		{
			ArrayList<String> data  = new ArrayList<String>(); 
			for(int j=0;j<headercount;j++)
			{
				//System.out.print(" - "+gridpanel.getBg().getView().getCell(i,j).getInnerText());
				data.add(bg.getView().getCell(i,j).getInnerText());
			}
			eo.addData(data);
		
		}
		
		return eo;
	}
}
